package swing;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Demo5 extends JFrame {
    public Demo5(){


        setBounds(100,100,217,167);
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

        Container conn = getContentPane();
        setLayout(null);
        String a [] = {"1","2","3","4","4","4","4","4"};
        DefaultListModel<String> model = new DefaultListModel<>();
        for(String tmp:a){
            model.addElement(tmp);
        }
        JList<String> j1 =new JList<>();
        j1.setModel(model);

        JScrollPane js =new JScrollPane(j1);
        js.setBounds(10,10,100,100);
        conn.add(js);


        ImageIcon icon = new ImageIcon("src\\swing\\teacher.png");
        JButton btn = new JButton(icon);



        conn.add(btn);

        btn.setBounds(120,60,70,25);
        btn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                java.util.List<String> values = j1.getSelectedValuesList();
                for(String tmp:values){
                    System.out.println(tmp);
                }
                System.out.println("----end-----");
            }
        });


        setVisible(true);





    }

    public static void main(String[] args) {

        new Demo5();
    }
}
